package com.egene.tw.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.text.TextUtils;

public class CheckUtil {
    private final static Pattern PHONE_PATTERN = Pattern.compile("[1]{1}[3,4,5,6,7,8]{1}[0-9]{9}");
    private final static Pattern EMAIL_PATTERN = Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");

    public static boolean checkPW(String pwd) {
        if (TextUtils.isEmpty(pwd)) {
            MToast.show("密碼為空");
            return false;
        }
        if (pwd.length() < 6 || pwd.length() > 12) {
            MToast.show("請輸入6-12位密碼");
            return false;
        }
        return true;
    }

    public static boolean checkEMail(String phone) {
        if (TextUtils.isEmpty(phone)) {
            MToast.show("郵箱不能為空");
            return false;
        }
        Matcher m = EMAIL_PATTERN.matcher(phone);
        if (!m.matches()) {
            MToast.show("郵箱格式錯誤");
            return false;
        }
        return true;
    }


    public static boolean checkPhone(String phone) {
        if (TextUtils.isEmpty(phone)) {
            MToast.show("手機號碼不能為空");
            return false;
        }
        return true;
    }
}
